﻿Imports System.IO
Imports Telerik.WinControls.UI

Public Class frmHRLettersLibrary

    Sub FillLibrary()
        Try
            Me.Cursor = Cursors.Default

            Dim Dir As New DirectoryInfo(FTPAddress + "HR Library")
            Dim DirFiles As FileInfo() = Dir.GetFiles()

            Me.GridArchive.Rows.Clear()

            'list the names of all files in the specified directory
            For Each DirSub As DirectoryInfo In Dir.GetDirectories
                For Each Fi As FileInfo In DirSub.GetFiles
                    Dim Row() As String = {Fi.FullName, DirSub.Name, Fi.Name, "Download"}
                    Me.GridArchive.Rows.Add(Row)
                Next
            Next

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub frmHRLettersLibrary_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized

        FillLibrary()
    End Sub

    Private Sub GridArchive_CommandCellClick(sender As Object, e As System.EventArgs) Handles GridArchive.CommandCellClick
        Try
            If Me.FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

                'Set files
                Dim SelFile As FileInfo
                Dim SelFilePath, ChosenFolderPath, DownloadPath As String

                SelFilePath = Me.GridArchive.CurrentRow.Cells(0).Value
                ChosenFolderPath = Me.FolderBrowserDialog1.SelectedPath

                SelFile = New FileInfo(SelFilePath)


                DownloadPath = ChosenFolderPath + "\" + SelFile.Name

                My.Computer.Network.UploadFile(SelFilePath, DownloadPath, FTPUserName, FTPPassword, True, 1000)

                'FillDocuments()
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class